package com.aaa.controller.census;

import com.aaa.entity.ResponseDto;
import com.aaa.service.UserService;
import com.aaa.service.impl.UserServiceImpl;
import com.aaa.util.DateUtils;
import com.google.gson.Gson;
import com.sun.xml.internal.messaging.saaj.packaging.mime.util.LineInputStream;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.Map;

@WebServlet("/GetUserByNearYearServlet")
public class GetUsertByNearYearServlet extends HttpServlet {
    UserService userService;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("application/json");
        Map<String,Object> map= userService.findUserCreatedTimeInfoForUserCount();
        ResponseDto responseDto = new ResponseDto();
        if (map != null) {
            responseDto.setStatus(ResponseDto.SUCCESS_CODE);
            responseDto.setData(map);
            responseDto.setMessage("操作成功");
        } else {
            responseDto.setStatus(ResponseDto.FAILURE_CODE);
            responseDto.setMessage("操作失败");
        }
        resp.getWriter().write(new Gson().toJson(responseDto));

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }

    @Override
    public void init(ServletConfig config) throws ServletException {
        userService = new UserServiceImpl();
    }
}